import { Global, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ConfigurationService } from './services/configuration.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './entities/user.entity';
import { UserService } from './services/user.service';
import { UtilityService } from './services/utility.service';
import { Role } from './entities/role.entity';
import { RoleService } from './services/role.service';
import { Access } from './entities/access.entity';
import { AccessService } from './services/access.service';
import { Tag } from './entities/tag.entity';
import { TagService } from './services/tag.service';
import { Article } from './entities/article.entity';
import { ArticleService } from './services/article.service';
import { Category } from './entities/category.entity';
import { CategoryService } from './services/category.service';
import { CosService } from './services/cos.service';
import { NotificationService } from './services/notification.service';
import { MailService } from './services/mail.service';
import { WordExportService } from './services/word-export.service';
import { PptExportService } from './services/ppt-export.service';
import { ExcelExportService } from './services/excel-export.service';
import { SettingService } from './services/setting.service';
import { MongooseModule } from '@nestjs/mongoose';
import { Setting, SettingSchema } from './schemas/setting.schema';
import { DashboardService } from './services/dashboard.service';
import { WeatherService } from './services/weather.service';
import { SystemService } from './services/system.service';
@Global()
@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    MongooseModule.forRootAsync({
      inject: [ConfigurationService],
      useFactory: (configurationService: ConfigurationService) => ({
        uri: configurationService.mongodbConfig.uri,
      }),
    }),
    MongooseModule.forFeature([
      {
        name: Setting.name,
        schema: SettingSchema,
      },
    ]),
    TypeOrmModule.forRootAsync({
      inject: [ConfigurationService],
      useFactory: (configurationService: ConfigurationService) => {
        return {
          type: 'mysql',
          ...configurationService.mysqlConfig,
          autoLoadEntities: true, // 自动加载所有实体
          synchronize: true, // 保持代码和数据库字段一致,开发时改成false
          logging: false, // 打印内部真实sql语句
        };
      },
    }),
    TypeOrmModule.forFeature([User, Role, Access, Tag, Article, Category]),
  ],
  providers: [
    ConfigurationService,
    UserService,
    UtilityService,
    RoleService,
    AccessService,
    TagService,
    ArticleService,
    CategoryService,
    CosService,
    NotificationService,
    MailService,
    WordExportService,
    PptExportService,
    ExcelExportService,
    SettingService,
    DashboardService,
    WeatherService,
    SystemService,
  ],
  exports: [
    ConfigurationService,
    UserService,
    UtilityService,
    RoleService,
    AccessService,
    TagService,
    ArticleService,
    CategoryService,
    CosService,
    NotificationService,
    MailService,
    WordExportService,
    PptExportService,
    ExcelExportService,
    SettingService,
    DashboardService,
    WeatherService,
    SystemService,
  ],
})
export class SharedModule {}
